package fr.cephb.joperon.core.db;


import com.sleepycat.db.DatabaseException;

import fr.cephb.joperon.core.Operon;
import fr.cephb.joperon.core.db.base.BaseLTermsDB;
import fr.cephb.joperon.core.entities.LTerms;
import fr.cephb.util.Pair;

public class LTermsDB extends BaseLTermsDB{

	public LTermsDB(Operon operon) {
		super(operon);
	}


	/**
	 * finds a term-id from a query
	 * @param query the term to search
	 * @return the term-id or null if it was not found
	 */
	public Integer getTermId(String query) throws DatabaseException
		{
		LTerms term= get(query.toLowerCase());
		return term==null?null:term.getTid();
		}
	


	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Operon op = Operon.newInstance();
			LTermsDB db= new LTermsDB(op);
			db.open();
			int i=0;
			LTermsDB.KeyValueIterator iter=db.listKeyValues();
			while(iter.hasNext())
				{
				Pair<String,LTerms> p=iter.next();
				//if(p.first().length()==0) continue;
				System.err.println("["+p.first()+"] "+p.second());
				if(++i==500) break;
				}
			iter.close();
			
			db.close();
			op.close();
		} catch (Exception e) {
		e.printStackTrace();
		}
		
	

	}

}
